package com.gismore.demo.config;

import com.gismore.demo.common.util.PropertiesUtils;
import com.gismore.demo.config.converter.DevModeConverter;
import com.gismore.demo.config.converter.LongExpressionConverter;
import org.aeonbits.owner.Config;
import org.aeonbits.owner.ConfigCache;

import java.util.Properties;
import java.util.Set;

/**
 * Created by lei on 2017/5/25.
 */

public interface AppConfig extends Config{


	@DefaultValue("true")
	@Key("env")
	@ConverterClass(DevModeConverter.class)
	Boolean devMode();

	@Separator(";")
	@Key("shiro.anon.urls")
	Set<String> shiroAnonUrls();

	@ConverterClass(LongExpressionConverter.class)
	@Key("shiro.token.jwt.ttl")
	Long jwtTTL();

	@Key("shiro.filterchain.definitions")
	String filterChainDefinitions();

	static AppConfig me(){
		String configKey = "appConfig";
		AppConfig ret;
		if(ConfigCache.get(configKey) == null){
			String configFileName = "application.properties";

			Properties properties = PropertiesUtils.loadConfigProperties(configFileName);

			ret = ConfigCache.getOrCreate(configKey,AppConfig.class, properties);
		}else {
			ret = ConfigCache.get(configKey);
		}
		return ret;
	}
}
